package com.wes.dsptest.data;

import android.content.Context;
import android.content.SharedPreferences;

public class TinySharedPreferences {

    private static TinySharedPreferences sInstance;
    private final SharedPreferences tsp;

    private TinySharedPreferences(Context context) {
        tsp = context.getSharedPreferences("yg_dsp_preference", Context.MODE_PRIVATE);
    }

    public static TinySharedPreferences instance(Context context) {
        if (sInstance == null) {
            synchronized (TinySharedPreferences.class) {
                if (sInstance == null) {
                    sInstance = new TinySharedPreferences(context);
                }
            }
        }
        return sInstance;
    }

    public void setStringValue(String key, String value) {
        SharedPreferences.Editor edit = tsp.edit();
        edit.putString(key, value);
        edit.commit();
    }

    public String getStringValue(String key, String def) {
        return tsp.getString(key, def);
    }

    public void setIntValue(String key, int value) {
        SharedPreferences.Editor edit = tsp.edit();
        edit.putInt(key, value);
        edit.commit();
    }

    public int getIntValue(String key, int defaultVal) {
        return tsp.getInt(key, defaultVal);
    }



    public void setBooleanValue(String key, boolean value) {
        SharedPreferences.Editor edit = tsp.edit();
        edit.putBoolean(key, value);
        edit.commit();
    }

    public boolean getBooleanValue(String key, boolean defaultVal) {
        return tsp.getBoolean(key, defaultVal);
    }

    public void removeKey(String key) {
        SharedPreferences.Editor edit = tsp.edit();
        edit.remove(key);
        edit.commit();
    }

    public boolean contains(String key) {
        return tsp.contains(key);
    }

}
